/*
 * 1479. 数组第二大数
 * 在数组中找到第二大的数
 * https://www.lintcode.com/problem/second-max-of-array/description
 * 
 * 样例
 * 给出 [1, 3, 2, 4], 返回 3.
 * 给出 [1, 2], 返回 1.
 * 
 * 2018.06.10 @jeyming
 */
package second_max_of_array_1479;

import java.util.Arrays;

public class Second_max_of_array_1479 {
	/**
	 * @param nums: An integer array
	 * @return: The second max number in the array.
	 */
	public static int secondMax(int[] nums) {
		// write your code here
		Arrays.sort(nums, 0, nums.length);
		if(nums.length == 1)
			return nums[0];
		else
			return nums[nums.length - 2];
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int nums[] = {1,3,2,4};
		System.out.println(secondMax(nums));

	}

}
